package injections.converters.atomic;

import injections.DefinedProperty;
import injections.converters.Converter;

import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by rehak on 2/14/14.
 */
public class AtomicBooleanConverter implements Converter {

    private static final Class<?>[] CLSS = new Class<?>[]{AtomicBoolean.class};
    private static final Set<Class<?>> SUP = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(CLSS)));

    @Override
    public Set<Class<?>> supportedClasses() {
        return SUP;
    }

    @Override
    public AtomicBoolean convertValue(List<DefinedProperty> props, Class<?> cls) {
        if (SUP.contains(cls)) {
            Boolean val = Boolean.parseBoolean(props.get(0).getValues().get(0).getVal()+"");
            return new AtomicBoolean(val);
        }
        throw new RuntimeException("Unsupported class for conversion " + cls);
    }
}
